import os

# 调用读Excel的第三方库xlrd
from xlrd import open_workbook

from commond import get_path_info


class ReadExcel(object):
    def __init__(self, project_name):
        self.path = os.path.join(get_path_info.get_test_project(project_name), 'testfile')

    def get_xls(self, xls_name, sheet_name):  # xls_name填写用例的Excel名称 sheet_name该Excel的sheet名称
        cls = []
        xlspath = os.path.join(self.path, xls_name)
        file = open_workbook(xlspath)  # 打开用例Excel
        sheet = file.sheet_by_name(sheet_name)  # 获得打开Excel的sheet
        # 获取这个sheet内容行数
        nrows = sheet.nrows
        for i in range(nrows):
            if sheet.row_values(i)[0] != u'case_name':  # 如果这个Excel的这个sheet的第i行的第一列不等于case_name把这行的数据添加到cls[]
                cls.append(sheet.row_values(i))

        return cls


if __name__ == '__main__':
    print(ReadExcel("WP").get_xls('WP.xlsx', 'login'))
